//
//  AppUserBaseModel.m
//  CarRentOutApp
//
//  Created by ferver7 on 2017/11/8.
//  Copyright © 2017年 ferver7. All rights reserved.
//

#import "AppUserBaseModel.h"

@implementation AppUserBaseModel
MJCodingImplementation
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}
+ (AppUserBaseModel *)sharedUserData{
    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *path = [documentPath stringByAppendingPathComponent:@"AppUserBaseModel.archiver"];
    AppUserBaseModel *userInfoModel =[NSKeyedUnarchiver unarchiveObjectWithFile:path];
//    if (!userInfoModel) {
//        userInfoModel = [[AppUserBaseModel alloc] init];
//        NSLog(@"----");
//    }
    return userInfoModel;
    
}

+ (void)storeUserInfoWithModel:(AppUserBaseModel *)model{
    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *path = [documentPath stringByAppendingPathComponent:@"AppUserBaseModel.archiver"];
    BOOL success=[NSKeyedArchiver archiveRootObject:model toFile:path];
    NSLog(@"%@\n:::%@", documentPath,path);
    if (success) {
         [[NSNotificationCenter defaultCenter] postNotificationName:@"appUserModelChange" object:nil];
        NSLog(@"个人信息成功存储到本地");
    }else{
        NSLog(@"个人信息存储到本地失败");
    }
    
}
+(void)deleateCashe
{
    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *path = [documentPath stringByAppendingPathComponent:@"AppUserBaseModel.archiver"];
    [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}
@end
